﻿/*
* Copyright (c) 2010-2012 Tesla Engine Group
* 
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
* 
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
* 
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/


using System;
using Tesla.Graphics;
using Tesla.Math;
using D3D = SlimDX.Direct3D10;

namespace Tesla.Direct3D10.Graphics {
    /// <summary>
    /// Concrete Direct3D10 implementation of <see cref="IEffectAnnotation"/>.
    /// </summary>
    public sealed class D3D10EffectAnnotation : IEffectAnnotation {
        //TODO: I really need to find a way to properly get annotation details (param type, row, column) to do error checking.

        private D3D.EffectVariable _annotation;
        private String _name;
        private String _semantic;
        private EffectParameterClass _paramClass;
        private EffectParameterType _paramType;
        private int _rowCount;
        private int _columnCount;

        /// <summary>
        /// Gets the annotation name.
        /// </summary>
        public String Name {
            get {
                return _name;
            }
        }

        /// <summary>
        /// Gets the semantic of the annotation.
        /// </summary>
        public String Semantic {
            get {
                return _semantic;
            }
        }

        /// <summary>
        /// Gets the parameter class of the annotation.
        /// </summary>
        public EffectParameterClass ParameterClass {
            get {
                return _paramClass;
            }
        }

        /// <summary>
        /// Gets the parameter type of the annotation.
        /// </summary>
        public EffectParameterType ParameterType {
            get {
                return _paramType;
            }
        }

        /// <summary>
        /// Gets the number of columns in the class of this parameter.
        /// </summary>
        public int ColumnCount {
            get {
                return _columnCount;
            }
        }

        /// <summary>
        /// Gets the number of rows in the class of this parameter.
        /// </summary>
        public int RowCount {
            get {
                return _rowCount;
            }
        }

        /// <summary>
        /// Creates a new instance of <see cref="D3D10EffectAnnotation"/>.
        /// </summary>
        /// <param name="annotation">The D3D10 effect annotation.</param>
        /// <param name="name">The annotation's name.</param>
        /// <param name="semantic">The annotation's semantic.</param>
        /// <param name="paramClass">The annotation's parameter class.</param>
        /// <param name="paramType">The annotation's parameter type.</param>
        internal D3D10EffectAnnotation(D3D.EffectVariable annotation, String name, String semantic, EffectParameterClass paramClass, EffectParameterType paramType) {
            _name = name;
            _annotation = annotation;
            _semantic = semantic;
            _paramClass = paramClass;

            //Need to find a way to properly get these values!
            _paramType = paramType;
            _columnCount = 0;
            _rowCount = 0;
        }

        /// <summary>
        /// Gets the value of the annotation as a bool.
        /// </summary>
        /// <returns>The bool value</returns>
        /// <exception cref="System.InvalidCastException">Thrown if not type bool and a scalar.</exception>
        public bool GetValueBool() {
            if(_paramClass != EffectParameterClass.Scalar) {
                throw new InvalidCastException();
            }
            return ((D3D.EffectScalarVariable) _annotation).GetBool();
        }

        /// <summary>
        /// Gets the value of the annotation as an int.
        /// </summary>
        /// <returns>The int value</returns>
        /// <exception cref="System.InvalidCastException">Thrown if not type int and a scalar.</exception>
        public int GetValueInt() {
            if(_paramClass != EffectParameterClass.Scalar) {
                throw new InvalidCastException();
            }
            return ((D3D.EffectScalarVariable) _annotation).GetInt();
        }

        /// <summary>
        /// Gets the value of the annotation as a single.
        /// </summary>
        /// <returns>The single value</returns>
        /// <exception cref="System.InvalidCastException">Thrown if not type single and a scalar.</exception>
        public float GetValueSingle() {
            if(_paramClass != EffectParameterClass.Scalar) {
                throw new InvalidCastException();
            }
            return ((D3D.EffectScalarVariable) _annotation).GetFloat();
        }

        /// <summary>
        /// Gets the value of the annotation as a string.
        /// </summary>
        /// <returns>The string value </returns>
        /// <exception cref="System.InvalidCastException">Thrown if not type string and an object.</exception>
        public String GetValueString() {
            if(_paramClass != EffectParameterClass.Object && _paramType != EffectParameterType.String) {
                throw new InvalidCastException();
            }
            return ((D3D.EffectStringVariable) _annotation).GetString();
        }

        /// <summary>
        /// Gets the value of the annotation as a matrix.
        /// </summary>
        /// <returns>The matrix value</returns>
        /// <exception cref="System.InvalidCastException">Thrown if not of a matrix class.</exception>
        public Matrix GetValueMatrix() {
            throw new NotImplementedException();
        }

        /// <summary>
        /// Gets the value of the annotation as a quaternion.
        /// </summary>
        /// <returns>The quaternion value</returns>
        /// <exception cref="System.InvalidCastException">Thrown if not of a vector class and proper row/column count.</exception>
        public Math.Quaternion GetValueQuaternion() {
            throw new NotImplementedException();
        }

        /// <summary>
        /// Gets the value of the annotation as a vector2.
        /// </summary>
        /// <returns>The vector2 value </returns>
        /// <exception cref="System.InvalidCastException">Thrown if not of a vector class and proper row/column count.</exception>
        public Vector2 GetValueVector2() {
            throw new NotImplementedException();
        }

        /// <summary>
        /// Gets the value of the annotation as a vector3.
        /// </summary>
        /// <returns>The vector3 value</returns>
        /// <exception cref="System.InvalidCastException">Thrown if not of a vector class and proper row/column count.</exception>
        public Vector3 GetValueVector3() {
            throw new NotImplementedException();
        }

        /// <summary>
        /// Gets the value of the annotation as a vector4.
        /// </summary>
        /// <returns>The vector4 value</returns>
        /// <exception cref="System.InvalidCastException">Thrown if not of a vector class and proper row/column count.</exception>
        public Vector4 GetValueVector4() {
            throw new NotImplementedException();
        }
    }
}
